﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using VIA.Foundation;
using VIA.Integration.Domain;
using VIA.Integration.LeadShine.Presentation.ViewModel;
using VIA.Presentation;

namespace VIA.Integration.LeadShine.Presentation.View
{
    /// <summary>
    /// AxisView.xaml 的交互逻辑
    /// </summary>
    [View(typeof(IAxisView))]
    public partial class AxisView : IAxisView
    {
        public AxisView()
        {
            InitializeComponent();
        }

        public IObject EditObject
        {
            get => this.GetViewModel<IObjectEditor>().EditObject;
            set => this.GetViewModel<IObjectEditor>().EditObject = value;
        }
        public DmcAxis Axis => this.GetViewModel<AxisViewModel>().Axis;
        private async void Bt_JogP_MouseUp(object sender, MouseButtonEventArgs e)
        {
            await Axis.PauseAsync();
        }

        private void Bt_JogP_MouseDown(object sender, MouseButtonEventArgs e)
        {
            _ = Axis.PostiveAsync();
        }

        private async void Bt_JogN_MouseUp(object sender, MouseButtonEventArgs e)
        {
            await Axis.PauseAsync();
        }

        private void Bt_JogN_MouseDown(object sender, MouseButtonEventArgs e)
        {
            _ = Axis.NegativeAsync();
        }
        private async void Bt_JogP_MouseLeave(object sender, MouseEventArgs e)
        {
            if (e.LeftButton == MouseButtonState.Pressed)
                await Axis.PauseAsync();
        }

        private async void Bt_JogN_MouseLeave(object sender, MouseEventArgs e)
        {
            if (e.LeftButton == MouseButtonState.Pressed)
                await Axis.PauseAsync();
        }
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            var bt = e.OriginalSource as Button;
            //var position = bt?.DataContext as AxisPointParam;
            //Model.Move(position);

        }

        private void DataGrid_CurrentCellChanged(object sender, EventArgs e)
        {
            dataGrid.CommitEdit(DataGridEditingUnit.Row, true);
        }
    }
}
